package com.sec.android.app.myfiles.module.download;

import android.content.Context;
import android.os.Bundle;

import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.provider.PrivateMyFilesProvider;

public class DownloadReloadStrategyImp extends AbsReloadStrategyImp {

    public DownloadReloadStrategyImp(Context context, NavigationInfo navigationInfo) {
        super(context, navigationInfo);
    }

    @Override
    public void reload(ReloadCause cause, Bundle extras, int event) {
        switch (cause) {
            case ContentChanged:
                if (mNavigationInfo != null) {
                    refreshDb();
                }
                break;
            case MediaScanFinished:
                if (mNavigationInfo != null) {
                    refreshDb();
                    AbsMyFilesFragment curFragment = mNavigationInfo.getCurFragment();
                    if (curFragment != null) {
                        curFragment.reload();
                    }
                }
                break;
            default:
                break;
        }

    }

    public void refreshDb() {
        FileRecord currentRecord = mNavigationInfo.getCurRecord();
        PrivateMyFilesProvider.refreshDb(mContext, currentRecord, false);
    }

}
